"use strict";
const path = require("path");
require("dotenv").config();
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");

function resolve(dir) {
    return path.join(__dirname, dir);
}
const { env = {} } = process;
const port = env.DEV_PORT || 3000;
/* 是否开发模式 */
const isDevMode = env.NODE_ENV === "development";
const plugins = [new HardSourceWebpackPlugin()];

let webpack = {
    resolve: {
        alias: {
            "@": resolve("src"),
        },
    },
    plugins
};

const config = {
    publicPath: "./",
    outputDir: 'dist', //  生产环境构建文件的目录
    assetsDir: "static",
    lintOnSave: false,
    productionSourceMap: isDevMode,
    parallel: true, //是否开启多线程
    devServer: {
        port: port,
        open: true,
        hot: true,
        overlay: {
            //  当出现编译器错误或警告时，在浏览器中显示全屏覆盖层
            warnings: false,
            errors: true,
        },
        openPage: "/index.html",
        proxy: {
            '/api': {
                target: env.VUE_APP_API_TAGRFET,
                ws: true,
                changOrigin: true,
                pathRewrite: {
                    '^/api': '/'
                }
            },
        }
    },
    configureWebpack: webpack,
};

module.exports = config;